<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>菜单调试工具</title>
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
      max-width: 800px;
      margin: 0 auto;
      padding: 20px;
      line-height: 1.6;
    }
    h1 {
      color: #333;
    }
    pre {
      background: #f5f5f5;
      padding: 15px;
      border-radius: 4px;
      overflow-x: auto;
    }
    .info-box {
      border: 1px solid #ddd;
      border-radius: 4px;
      padding: 15px;
      margin-bottom: 20px;
    }
    .success {
      border-color: #4CAF50;
      background-color: #f1f8e9;
    }
    .error {
      border-color: #f44336;
      background-color: #ffebee;
    }
    button {
      background-color: #2196F3;
      color: white;
      border: none;
      padding: 10px 15px;
      border-radius: 4px;
      cursor: pointer;
    }
    button:hover {
      background-color: #0b7dda;
    }
  </style>
</head>
<body>
  <h1>菜单调试工具</h1>
  
  <div class="info-box">
    <h2>localStorage 用户信息</h2>
    <pre id="userInfoOutput"></pre>
  </div>
  
  <div class="info-box">
    <h2>菜单配置检查</h2>
    <pre id="menuCheckOutput"></pre>
  </div>
  
  <div class="info-box">
    <h2>角色信息检查</h2>
    <pre id="roleCheckOutput"></pre>
  </div>
  
  <div class="info-box">
    <h2>路由信息</h2>
    <pre id="routeInfoOutput"></pre>
  </div>
  
  <button onclick="checkLocalStorage()">检查 localStorage</button>
  <button onclick="clearUserInfo()">清除用户信息</button>
  <button onclick="simulateAdminUser()">模拟管理员用户</button>
  <button onclick="simulateProductManager()">模拟产品经理用户</button>
  
  <script>
    function checkLocalStorage() {
      // 检查用户信息
      const userInfo = localStorage.getItem('userInfo');
      const token = localStorage.getItem('token');
      
      const userInfoOutput = document.getElementById('userInfoOutput');
      if (userInfo) {
        try {
          const parsedUserInfo = JSON.parse(userInfo);
          userInfoOutput.textContent = JSON.stringify(parsedUserInfo, null, 2);
          
          // 角色信息检查
          const roleCheckOutput = document.getElementById('roleCheckOutput');
          const hasRoles = parsedUserInfo.hasOwnProperty('roles');
          const rolesType = hasRoles ? typeof parsedUserInfo.roles : '不存在';
          const isArray = hasRoles ? Array.isArray(parsedUserInfo.roles) : false;
          
          roleCheckOutput.textContent = `角色字段存在: ${hasRoles}\n`;
          roleCheckOutput.textContent += `角色类型: ${rolesType}\n`;
          roleCheckOutput.textContent += `是否为数组: ${isArray}\n`;
          if (hasRoles && isArray) {
            roleCheckOutput.textContent += `角色列表: ${parsedUserInfo.roles.join(', ')}\n`;
            roleCheckOutput.textContent += `包含ADMIN角色: ${parsedUserInfo.roles.includes('ADMIN')}\n`;
            roleCheckOutput.textContent += `包含PRODUCT_MANAGER角色: ${parsedUserInfo.roles.includes('PRODUCT_MANAGER')}\n`;
          }
          
          // 菜单配置检查
          const menuCheckOutput = document.getElementById('menuCheckOutput');
          const expectedMenuItems = [
            '/dashboard/product/list',
            '/dashboard/product/members',
            '/dashboard/product/requirements',
            '/dashboard/product/test-versions'
          ];
          
          menuCheckOutput.textContent = '预期产品管理菜单项:\n';
          expectedMenuItems.forEach((item, index) => {
            menuCheckOutput.textContent += `${index + 1}. ${item}\n`;
          });
          
          // 路由信息
          const routeInfoOutput = document.getElementById('routeInfoOutput');
          routeInfoOutput.textContent = `当前URL: ${window.location.href}\n`;
          routeInfoOutput.textContent += `令牌存在: ${!!token}\n`;
          
        } catch (e) {
          userInfoOutput.textContent = '用户信息解析错误: ' + e.message;
        }
      } else {
        userInfoOutput.textContent = '未找到用户信息';
      }
    }
    
    function clearUserInfo() {
      if (confirm('确定要清除用户信息吗？这将需要重新登录。')) {
        localStorage.removeItem('userInfo');
        localStorage.removeItem('token');
        alert('用户信息已清除');
        checkLocalStorage();
      }
    }
    
    function simulateAdminUser() {
      const mockAdminUser = {
        id: 'admin123',
        realName: '管理员',
        username: 'admin',
        roles: ['ADMIN', 'PRODUCT_MANAGER']
      };
      localStorage.setItem('userInfo', JSON.stringify(mockAdminUser));
      alert('已设置模拟管理员用户');
      checkLocalStorage();
    }
    
    function simulateProductManager() {
      const mockProductManager = {
        id: 'pm123',
        realName: '产品经理',
        username: 'product_manager',
        roles: ['PRODUCT_MANAGER']
      };
      localStorage.setItem('userInfo', JSON.stringify(mockProductManager));
      alert('已设置模拟产品经理用户');
      checkLocalStorage();
    }
    
    // 页面加载时自动检查
    window.onload = checkLocalStorage;
  </script>
</body>
</html>